﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using BBB.Valuta.Entity;

namespace BBB.Valuta
{
    public enum CatalogType
    {
        Valuta, Department, Printer
    }

    public partial class CatalogForm : Form
    {


        public CatalogForm(CatalogType catalogType)
        {
            InitializeComponent();
            catalogDataGridView.AutoGenerateColumns = true;

            if (catalogType == CatalogType.Department)
            {
                this.Text = "Підрозділи";
                BindingList<Department> dep = new BindingList<Department>(Settings.GetInstance().Departments);
                catalogBindingSource.DataSource = dep;
            }
            if (catalogType == CatalogType.Valuta)
            {
                this.Text = "Валюта";
                BindingList<Entity.Valuta> dep = new BindingList<Entity.Valuta>(Settings.GetInstance().Valuta);
                catalogBindingSource.DataSource = dep;
            }
            if (catalogType == CatalogType.Printer)
            {
                this.Text = "Принтери";
                BindingList<Printer> dep = new BindingList<Printer>(Settings.GetInstance().Printers);
                catalogBindingSource.DataSource = dep;
            }
        }

        private void CatalogForm_FormClosed(object sender, FormClosedEventArgs e)
        {
            Settings.SaveSettings();
        }

        private void catalogDataGridView_CellValidating(object sender, DataGridViewCellValidatingEventArgs e)
        {
            if ((string) e.FormattedValue == string.Empty)
            {
                e.Cancel = true;
                MessageBox.Show("Заповніть поля", "", MessageBoxButtons.OK, MessageBoxIcon.Warning);
               
            }
            else
            {
                e.Cancel = false;
            }
        }

        private void CatalogForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = !Validate();
        }
    }
}
